<!DOCTYPE html>
<html lang="zh-CN">
	<head>
		<style>
			html,
			body {
				width: 100%;
				height: 100%;
				margin: 0;
				padding: 0;
				background-color: #fff;
			}

			.cad-view {
				width: 100%;
				height: 100%;
				overflow: auto;
				margin: 0;
				padding: 0;
				box-sizing: border-box;
				display: flex !important;
				justify-content: center;
				border: 1px solid rgb(0 0 0 / 0.2);
			}

			#close {
				width: 50px;
				height: 50px;
				text-align: center;
				line-height: 50px;
				font-size: 30px;
				position: fixed;
				right: 20px;
				top: 20px;
			}
		</style>
		<script type="text/javascript" src="dxf-parser.js"></script>
		<script type="module" src="three-dxf-gai.es.js"></script>
		<script type="text/javascript" src="uni.webview.1.5.4.js"></script>
	</head>
	<body>
		<noscript>
			<strong>Please enable JavaScript to continue.</strong>
		</noscript>
		<div id="cad-view" class="cad-view"></div>
		<div id="close">X</div>
		<script type="module">
			const viewEl = document.getElementById('cad-view')
			const closeEl = document.getElementById('close')
			const parser = new DxfParser()
			let content = ''
			let scale = 1

			const initDxf = (string, width, height, fontUrl) => {
				var dxf = parser.parseSync(string)
				viewEl.innerHTML = ''
				threeDxfViewer(dxf, viewEl, width, height, fontUrl)
			}

			const params = new URLSearchParams(location.search)

			const style = getComputedStyle(viewEl)
			let width = Number.parseFloat(style.getPropertyValue('width'))
			let height = Number.parseFloat(style.getPropertyValue('height'))

			fetch(params.get('src')).then(res => res.text()).then(res => {
				content = res
				initDxf(content, width, height, params.get('fontUrl'))
			})

			closeEl.addEventListener('click', (e) => {
				uni.postMessage({
					data: {
						action: 'close'
					}
				});
			})
		</script>
	</body>

	<script>
		document.addEventListener('UniAppJSBridgeReady', function() {
			uni.webView.getEnv(function(res) {
				// console.log('当前环境：' + JSON.stringify(res));
			});
			// uni.webView.navigateTo(...)
		});
	</script>
</html>